<?php
namespace app\controller;
use app\exception\Failure;
use app\exception\RequestMethodInvalidate;
use app\exception\Success;
use app\facade\logic\User as FaUserLogic;


class User extends AuthBase{
    //
    /**
     * info
     * @Route("/user/info")
     */
    public function info(){

        if($this->request->isPost()){
            $user =  FaUserLogic::getUserByUserId();
            throw new Success($user);
        }

        throw new RequestMethodInvalidate();
    }

    /**
     * del
     * @Route("/user/del")
     */
    public function del(){
        if($this->request->isPost()){
            $result = FaUserLogic::del();
            if($result){
                throw new Success();
            }else{
                throw new Failure();
            }
        }
        throw new RequestMethodInvalidate();
    }

    /**
     * update
     * @Route("/user/update")
     */
    public function update(){
        if($this->request->isPost()){
            $result = FaUserLogic::update();
            if($result){
                throw new Success();
            }else{
                throw new Failure();
            }
        }
    }

    /**
     * create
     * @Route("/user/create")
     */
    public function create(){
        if($this->request->isPost()){
            $result = FaUserLogic::create();
            if($result){
                throw new Success();
            }else{
                throw new Failure();
            }
        }
    }

    /**
     * create
     * @Route("/user/list")
     */
    public function list(){
        if($this->request->isPost()){
            $list = FaUserLogic::getUserList();
            throw new Success($list);
        }
        throw new RequestMethodInvalidate();
    }

    // Logout
    public function logout(){

        if($this->request->isPost()){
            // Clear Session And Delete Login Token
            FaUserLogic::logout();
        }

        throw new RequestMethodInvalidate();
    }
}
 
